package com.ECPDemo.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.ECPDemo.mapper.ItemDescMapper;
import com.ECPDemo.mapper.ItemMapper;
import com.ECPDemo.pojo.Item;
import com.ECPDemo.pojo.ItemDesc;
import com.ECPDemo.service.ItemService;
import com.github.pagehelper.PageHelper;

 
@Service
public class ItemServiceImpl implements ItemService{

	Log log = LogFactory.getLog(ItemServiceImpl.class);
	
	
	
	@Resource
	private ItemMapper itemMapper;
	
	@Resource
	private ItemDescMapper itemDescMapper;

	@Override
	public Item getItemById(long itemId) {
		log.info("getItemById ----> parameter : itemId : " + itemId);
		
		Item item = new Item(itemId);
		
		List<Item> itemList = itemMapper.queryItmeList(item);
		if (itemList == null || itemList.size() <1) {
			return null;
		}
		return itemList.get(0);
		
	}

	@Override
	public List<Item> getItemList(Item item,Integer page, Integer rows) {
		//分页处理
		PageHelper.startPage(page, rows);
		log.info("getItemList ----> parameter : " + item.toString() + "page : " + page + " rows : " + rows);
		//执行查询
		return itemMapper.queryItmeList(item);
	}

	@Override
	public ItemDesc getItemDescByItemId(long itemId) {
		log.info("getItemDescByItemId ----> parameter : itemId : " + itemId);
		return  itemDescMapper.queryItemDescByItemId(itemId);
	}

	@Override
	public Integer getItemListCount(Item item) {
		log.info("getItemListCount ----> parameter : item : " + item.toString());
		return itemMapper.queryItemListCount(item);
	}
	
	
	
}
